package com.zxbit.flash.presenter;

import com.zxbit.flash.BuildConfig;
import com.zxbit.flash.base.BasePresenter;
import com.zxbit.flash.common.UserInfo;
import com.zxbit.flash.mvpview.PayMethodMvpView;
import com.zxbit.flash.network.CustomConsumer;
import com.zxbit.flash.network.ExceptionHandle;
import com.zxbit.flash.network.ParamsFactory;
import com.zxbit.flash.response.PayCodeResponse;
import com.zxbit.flash.response.PayCodeResponseNew;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.functions.Consumer;

public class PayMethodPresenter extends BasePresenter {
    private PayMethodMvpView mvpView;
    public PayMethodPresenter(PayMethodMvpView mvpView){
        this.mvpView=mvpView;
    }

    /**
     * 获取还款码
     * @param orderId
     */
    public void getPayCodeNew(String orderId){
        Map<String, Object> formMap = new HashMap<>();
        formMap.put("orderId", orderId);
        formMap.put("flag", "normal");
        formMap.put("channel", BuildConfig.channel);
        toSubScribe(req.getPayCodeDataNew(UserInfo.getToken(), ParamsFactory.getCommonParams(formMap)), new CustomConsumer<PayCodeResponseNew>() {
            @Override
            public void call(PayCodeResponseNew payCodeResponse) {
                mvpView.onGetDataNext(payCodeResponse);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                ExceptionHandle.handleException(throwable);
                mvpView.onGetDataError(throwable);
            }
        });
    }

    public void getRollovePayCode(String orderId){
        Map<String, Object> formMap = new HashMap<>();
        formMap.put("orderId", orderId);
        toSubScribe(req.getRolloverPayCodeData(BuildConfig.channel, UserInfo.getToken(), ParamsFactory.getCommonParams(formMap)), new CustomConsumer<PayCodeResponse>() {
            @Override
            public void call(PayCodeResponse payCodeResponse) {
                mvpView.onGetDataNext(payCodeResponse);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                ExceptionHandle.handleException(throwable);
                mvpView.onGetDataError(throwable);
            }
        });
    }
}
